package modele;

public class TakeResourceAction<R extends Resource> extends
		ResourcePoolAction<R> {

	public TakeResourceAction(ResourcePool<R> pool, ResourcefulUser<R> usr) {
		this.pool = pool;
		this.rfu = usr;
	}

	@Override
	public void tryAction() {
		if (pool.hasAvailableResource()) {
			R res = this.pool.provideRessource();
			rfu.setRessource(res);
			System.out.println("(" + res.description() + " taken. "
					+ pool.availableResource.size() + " left.)");
		} else
			System.out.println("(Fail)");
	}

	@Override
	public boolean isReady() {
		return (rfu.getRessource() == null);
	}

	@Override
	public boolean isFinished() {
		return (rfu.getRessource() != null);
	}

}
